<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class daftar_member extends CI_Controller {

	function __construct(){
		parent::__construct();

		$this->load->helper('bara_helper');
		$this->load->library('bara_lib');
		
		$this->load->library('recaptcha');

		$this->load->model('modul/login_member_model');

		$this->load->model('modul/model_menu');

		$this->load->model('modul/about_model');
		$this->load->model('modul/article_model');
		$this->load->model('modul/sosmed_model');

	}
    function index() {

    	$data['text_home'] = "Home";
		$data['text_title'] = "Daftar";

        $this->load->helper(array('form','html'));
		
        $data['recaptcha_html'] = $this->recaptcha->recaptcha_get_html();

		$data['content'] = 'frontend/'. $this->bara_lib->theme() .'/modul/member/member_daftar';

		
		//menu
		$data['get_menus'] = $this->model_menu->get_menu($this->bara_lib->language());

		// sosmed
		$data['gets_facebook'] = $this->sosmed_model->get_sosmed('facebook');
		$data['gets_twitter'] = $this->sosmed_model->get_sosmed('twitter');
		$data['gets_sosmed'] = $this->sosmed_model->get_sosmed_all();

		//footer
		$data['gets_about_footer'] = $this->about_model->get_about('about_us',$this->bara_lib->language());
		$data['get_articles_footer'] = $this->article_model->get_article($this->bara_lib->language(),3,0);
		//end footer

		$data['head'] = 'layout/'. $this->bara_lib->theme() .'/head';
		$data['menu'] = 'layout/'. $this->bara_lib->theme() .'/menu';
		$data['footer'] = 'layout/'. $this->bara_lib->theme() .'/footer';
		$this->load->view('layout/'. $this->bara_lib->theme() .'/inner', $data);   
    }

    function daftar() {

    	$this->form_validation->set_rules('nama_member', 'Nama', 'trim|required|min_length[3]|xss_clean');
		$this->form_validation->set_rules('username_member', 'Username', 'trim|required|min_length[5]|xss_clean');
		$this->form_validation->set_rules('password_member', 'Password', 'trim|required|min_length[5]|xss_clean');

		if ($this->form_validation->run() == FALSE)
		{
			$data['text_home'] = "Home";
		$data['text_title'] = "Daftar";

        $this->load->helper(array('form','html'));
		
		$data['content'] = 'frontend/'. $this->bara_lib->theme() .'/modul/member/member_daftar';

		
		//menu
		$data['get_menus'] = $this->model_menu->get_menu($this->bara_lib->language());

		// sosmed
		$data['gets_facebook'] = $this->sosmed_model->get_sosmed('facebook');
		$data['gets_twitter'] = $this->sosmed_model->get_sosmed('twitter');
		$data['gets_sosmed'] = $this->sosmed_model->get_sosmed_all();

		//footer
		$data['gets_about_footer'] = $this->about_model->get_about('about_us',$this->bara_lib->language());
		$data['get_articles_footer'] = $this->article_model->get_article($this->bara_lib->language(),3,0);
		//end footer

		$data['head'] = 'layout/'. $this->bara_lib->theme() .'/head';
		$data['menu'] = 'layout/'. $this->bara_lib->theme() .'/menu';
		$data['footer'] = 'layout/'. $this->bara_lib->theme() .'/footer';
		$this->load->view('layout/'. $this->bara_lib->theme() .'/inner', $data);   
		}
		else
		{

			$this->recaptcha->recaptcha_check_answer();

			if(!$this->recaptcha->getIsValid()){
				echo "<script>alert('Captcha Salah!');</script>";
				redirect(base_url('modul/daftar_member'), 'refresh');
			}
			else if($this->input->post('password_member') != $this->input->post('password_repeat')){
				echo "<script>alert('Password Tidak Sama!');</script>";
				redirect(base_url('modul/daftar_member'), 'refresh');
			}
			else {
		    	$data_member = array(
						'nama_member' => $this->input->post('nama_member'),
						'username_member' => $this->input->post('username_member'),
						'password_member' => MD5($this->input->post('password_member')),
						);

				$this->db->insert('member', $data_member);

				echo "<script>alert('Daftar Berhasil, Silahkan Login!');</script>";

				redirect(base_url('modul/login_member'), 'refresh');
			}

		}
    }
}